<template>
    <div class="card-box">
        <el-row>
            <el-col :md="10" :offset="7">
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="110px" class="demo-ruleForm">
                    <el-form-item label="客户名称：" prop="name">
                        <el-input v-model="ruleForm.name" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="市场类别：" prop="category">
                        <el-input v-model="ruleForm.category" auto-complete="off" placeholder="公众" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="客户类型：" prop="customer_type" v-show="$route.fullPath == '/agent_increase/new' || $route.fullPath =='/agent_increase/edit'">
                        <el-select v-model="ruleForm.customer_type" filterable placeholder="请选择" class="select">
                            <el-option v-for="item in customer_type" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="登录用户名：" prop="username">
                        <el-input v-model="ruleForm.username" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="登录密码：" prop="password">
                        <el-input type="password" v-model="ruleForm.password" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="联系人：" prop="user">
                        <el-input v-model="ruleForm.user" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="联系邮箱：" prop="email">
                        <el-input type="email" v-model="ruleForm.email" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="联系电话：" prop="phone">
                        <el-input type="number" v-model="ruleForm.phone" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="支付方式：" prop="pay">
                        <el-select v-model="ruleForm.pay" filterable placeholder="请选择" class="select">
                            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="预付款：" prop="yufu" v-show="ruleForm.pay == '选项1'">
                        <el-input type="number" v-model="ruleForm.pay" step="0.01" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="信用额度：" prop="xinyong" v-show="ruleForm.pay == '选项2'">
                        <el-input type="number" v-model="ruleForm.xinyong" step="0.01" auto-complete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="是否显示API：">
                        <el-checkbox-group v-model="ruleForm.isShow">
                            <el-checkbox></el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
                        <el-button @click="resetForm('ruleForm')">取消</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                options: [{
                    value: '选项1',
                    label: '预付'
                }, {
                    value: '选项2',
                    label: '后付'
                }],
                customer_type:[
                    {
                        value: '选项1',
                        label: '分销商'  
                    },
                    {
                        value: '选项2',
                        label: '企业'  
                    }
                ],
                ruleForm: {
                    name: '',
                    username: '',
                    password: '',
                    user: '',
                    email: '',
                    phone: '',
                    pay: '',
                    yufu: '',
                    xinyong: '',
                    customer_type: ''
                },
                rules: {
                    name: [{
                        required: true,
                        message: '请输入客户名称',
                        trigger: 'blur'
                    }],
                    username: [{
                        required: true,
                        message: '请输入登录用户名',
                        trigger: 'blur'
                    }],
                    password: [{
                        required: true,
                        message: '请输入登录密码',
                        trigger: 'blur'
                    }],
                    user: [{
                        required: true,
                        message: '请输入联系人',
                        trigger: 'blur'
                    }],
                    email: [{
                            required: true,
                            message: '请输入联系邮箱',
                            trigger: 'blur'
                        },
                        {
                            type: 'email',
                            message: '请输入正确的邮箱',
                            trigger: ['blur', 'change']
                        }
                    ],
                    phone: [{
                        required: true,
                        message: '请输入联系电话',
                        trigger: 'blur'
                    }],
                    pay: [{
                        required: true,
                        message: '请输入支付方式',
                        trigger: 'change'
                    }],
                    yufu: [{
                            required: true,
                            message: '请输入预付款',
                            trigger: 'blur'
                        },
                        {
                            pattern: /^\d+$/,
                            message: '预付款不能为负数'
                        }
                    ],
                    xinyong: [{
                            required: true,
                            message: '请输入信用额度',
                            trigger: 'blur'
                        },
                        {
                            pattern: /^\d+$/,
                            message: '信用额度不能为负数'
                        }
                    ],
                    customer_type: [
                        {
                            required: true,
                            message: '请选择客户类型',
                            trigger: 'change'
                        }
                    ]
                }
            };
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        // this.$axios.post('/api/carriers').then((res) => {
                        //     console.log('提交成功')
                        // })
                        console.log(111)
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
                if (this.$route.fullPath == '/agent_increase/new' || this.$route.fullPath == '/agent_increase/edit') {
                    this.$router.push({
                    path: '/agent_increase'
                    })
                } else {
                    this.$router.push({
                    path: '/agent_profit'
                    })
                }
                
            }
        }
    }
</script>

<style lang="scss" scoped>
    .select {
        width: 100%;
    }
</style>

